05. Challenge 2
Control Flow
In this quiz, I want you to write a for loop. Your loop will live inside a function that will be passed an int, n, and a string, str. Your loop should print the str n times.
There's another twist here - you will not need to touch main.cpp this time. Instead, your code will be written inside the eponymous function in PrintString.cpp. Make note of the way that main.cpp #includes PrintString.h. You'll be #includeing files soon.
Task Feedback:
Awesome! Make sure you test it.
Start Quiz:
#include <iostream>
#include <string>
#include <PrintString.h>
// it's also worth noting that `string` and `cout` live in namespace std, eg. `std::string`.
// with the declaration on the next line, you can just use `string` and `cout`.
using namespace std;
void PrintString(string str, int n)
{
// your code goes here! print str n times. Follow each str with a newline,
// eg. cout << str << endl;
}
/*
No need to change this file (unless you want to change the test case below).
*/
#include <iostream>
#include <PrintString.h>
using namespace std;
int main()
{
PrintString("This is a test.", 10);
}
/*
This header file defines the function signature for PrintString.
*/
#include <string>
void PrintString(std::string, int);